import React from 'react'
import { IconProps } from 'react-native-vector-icons/Icon'

import * as OcticonsLegacy from '../octicons/Octicons'
import IconSet from './generated/Octicons2'

export const Octicons = React.forwardRef<
  OcticonsLegacy.Octicons,
  OcticonIconProps
>((props, ref) => {
  const initialName = props.name || 'mark-github'

  const heights = props.size && props.size < 16 ? [16, 24] : [24, 16]
  const existingHeight = heights.find((h) =>
    IconSet.hasIcon(`${initialName}-${h}` as any) ? h : undefined,
  )

  if (props.name && !existingHeight) {
    return React.createElement(OcticonsLegacy.Octicons, props as IconProps)
  }

  const fixedName = `${initialName}-${existingHeight}`

  return React.createElement(IconSet as any, { ...props, ref, name: fixedName })
}) as any as typeof OcticonsLegacy.Octicons
export type Octicons = OcticonsLegacy.Octicons

export interface OcticonIconProps
  extends Omit<OcticonsLegacy.OcticonIconProps, 'name'> {
  name: OcticonIconName
}
export type OcticonIconName =
  | (OcticonsLegacy.OcticonIconName & 'keyboard')
  | 'alert'
  | 'archive'
  | 'arrow-both'
  | 'arrow-down'
  | 'arrow-down-left'
  | 'arrow-down-right'
  | 'arrow-left'
  | 'arrow-right'
  | 'arrow-up'
  | 'arrow-up-left'
  | 'arrow-up-right'
  | 'beaker'
  | 'bell'
  | 'bell-fill'
  | 'bell-slash'
  | 'bold'
  | 'book'
  | 'bookmark'
  | 'bookmark-fill'
  | 'bookmark-slash'
  | 'bookmark-slash-fill'
  | 'broadcast'
  | 'calendar'
  | 'check'
  | 'check-circle'
  | 'check-circle-fill'
  | 'checklist'
  | 'chevron-down'
  | 'chevron-left'
  | 'chevron-right'
  | 'chevron-up'
  | 'circle'
  | 'circle-slash'
  | 'clippy'
  | 'clock'
  | 'code'
  | 'code-review'
  | 'code-square'
  | 'comment'
  | 'comment-discussion'
  | 'commit'
  | 'copy'
  | 'cpu'
  | 'credit-card'
  | 'cross-reference'
  | 'dash'
  | 'database'
  | 'desktop-download'
  | 'device-camera-video'
  | 'device-desktop'
  | 'device-mobile'
  | 'diff'
  | 'diff-added'
  | 'diff-ignored'
  | 'diff-modified'
  | 'diff-removed'
  | 'diff-renamed'
  | 'dot'
  | 'dot-fill'
  | 'download'
  | 'eye'
  | 'eye-closed'
  | 'eye-slash'
  | 'file'
  | 'file-binary'
  | 'file-code'
  | 'file-diff'
  | 'file-directory'
  | 'file-directory-fill'
  | 'file-media'
  | 'file-submodule'
  | 'file-symlink'
  | 'file-symlink-file'
  | 'file-zip'
  | 'filter'
  | 'fire'
  | 'flame'
  | 'fold'
  | 'fold-down'
  | 'fold-up'
  | 'gear'
  | 'gift'
  | 'git-branch'
  | 'git-commit'
  | 'git-compare'
  | 'git-fork'
  | 'git-merge'
  | 'git-pull-request'
  | 'globe'
  | 'grabber'
  | 'graph'
  | 'heading'
  | 'heart'
  | 'heart-fill'
  | 'history'
  | 'home'
  | 'home-fill'
  | 'horizontal-rule'
  | 'hourglass'
  | 'hubot'
  | 'image'
  | 'inbox'
  | 'infinity'
  | 'info'
  | 'insights'
  | 'issue-closed'
  | 'issue-opened'
  | 'issue-reopened'
  | 'italic'
  | 'kebab-horizontal'
  | 'key'
  | 'law'
  | 'light-bulb'
  | 'link'
  | 'link-external'
  | 'list-ordered'
  | 'list-unordered'
  | 'location'
  | 'lock'
  | 'logo-gist'
  | 'logo-github'
  | 'mail'
  | 'mark-github'
  | 'markdown'
  | 'megaphone'
  | 'mention'
  | 'milestone'
  | 'mirror'
  | 'mortar-board'
  | 'mute'
  | 'no-entry'
  | 'north-star'
  | 'note'
  | 'octoface'
  | 'organization'
  | 'package'
  | 'package-dependencies'
  | 'package-dependents'
  | 'paper-airplane'
  | 'pencil'
  | 'people'
  | 'person'
  | 'pin'
  | 'play'
  | 'plug'
  | 'plus'
  | 'plus-circle'
  | 'project'
  | 'pulse'
  | 'question'
  | 'quote'
  | 'reply'
  | 'repo'
  | 'repo-forked'
  | 'repo-push'
  | 'repo-template'
  | 'report'
  | 'rocket'
  | 'rss'
  | 'screen-full'
  | 'screen-normal'
  | 'search'
  | 'server'
  | 'settings'
  | 'share'
  | 'share-android'
  | 'shield'
  | 'shield-check'
  | 'shield-lock'
  | 'shield-x'
  | 'sign-in'
  | 'sign-out'
  | 'skip'
  | 'smiley'
  | 'star'
  | 'star-fill'
  | 'stop'
  | 'stopwatch'
  | 'sync'
  | 'tab'
  | 'tag'
  | 'tasklist'
  | 'telescope'
  | 'terminal'
  | 'three-bars'
  | 'thumbsdown'
  | 'thumbsup'
  | 'tools'
  | 'trash'
  | 'trashcan'
  | 'triangle-down'
  | 'triangle-left'
  | 'triangle-right'
  | 'triangle-up'
  | 'typography'
  | 'unfold'
  | 'unlock'
  | 'unmute'
  | 'unverifed'
  | 'unverified'
  | 'upload'
  | 'verified'
  | 'versions'
  | 'workflow'
  | 'x'
  | 'x-circle'
  | 'x-circle-fill'
